﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WP_GasTracker.ViewModels;
using WP_GasTracker.Models;

namespace WP_GasTracker.Views
{
    public partial class ListPage : PhoneApplicationPage
    {
        public ListPage()
        {
            InitializeComponent();
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var vm = new ListViewModel();
            LayoutRoot.DataContext = vm;
            vm.Load();
        }

        private void Add_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/AddEditPage.xaml", UriKind.Relative));
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listbox = (ListBox)sender;
            var entry = (NotebookEntry)listbox.SelectedItem;
            var uri = "/Views/AddEditPage.xaml?id=" + entry.Id;
            NavigationService.Navigate(new Uri(uri, UriKind.Relative));
        }
    }
}